/*
EvoGen, Evolutionary Geneura is a framework for simulating distributed evolutionary computation experiments
Copyright (C) 2008 Junta de Andalucia CICE project P06-TIC-02025

This file is part of EvoGen.

EvoGen is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

EvoGen is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with EvoGen; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

contact:  http://geneura.ugr.es, https://forja.rediris.es/svn/geneura/evogen
*/
package mirabilis.org.config;

import random.CommonState;



public class Configuration {
	
	//Algorithms
	//GGA
	//EGA Elitist Generational GA
	
	public static double lower_bound = -1;
	public static double upper_bound = -1;
	public static double[] bounds;
	
	public static boolean minimization = true;
	public static long seed;
	//Number of dimensions N
	// The N-simplex has N+1 vertices
	public static int N;
	
	//For CEC2014 benchmark
	public static int F = 0; // Function no. from 1 to 30. 0 means that the framework is processing other type of problem.
	
	public static String evaluation = "snt.samples.combinatorial.OneMax";
	
	public static long termination_max_evaluation = 1000000;
	public static boolean termination_not_improved = false;
	public static boolean termination_hit_value = false;
	public static boolean termination_hit_value_sleep = false;
	public static double termination_value_is_reached = Double.MIN_VALUE;

			
	
	public static boolean statistic_n_evaluation = true;
	public static boolean statistic_time = true;
	public static boolean statistic_best = true;
	public static boolean statistic_avg = true;
	public static long statistic_sample = 400; 
	
	public static String logfile = "";
		
	
	public static LoadProperties prop;
	
	
	
	
	public static void setConfiguration(LoadProperties lp){
		prop = lp;
		minimization = Boolean.valueOf(lp.getProperty("minimization","false")).booleanValue();
		

		seed = (lp.getProperty("seed") == null) ? System.currentTimeMillis() : Long.valueOf(lp.getProperty("seed")).longValue();
		N = Integer.valueOf(lp.getProperty("N", "120")).intValue();
		lower_bound = Double.valueOf(lp.getProperty("lowerbound","-1")).doubleValue();
		upper_bound = Double.valueOf(lp.getProperty("upperbound","-1")).doubleValue();
		
		
		
		
				
		F = Integer.valueOf(lp.getProperty("F", "0")).intValue();
		
		
		evaluation = lp.getProperty("evaluation", "snt.samples.combinatorial.OneMax");
		
		
		termination_max_evaluation = Long.valueOf(lp.getProperty("terminationmaxevaluation", "120000")).longValue();
		termination_hit_value = Boolean.valueOf(lp.getProperty("terminationhitvalue", "false")).booleanValue();	
		termination_hit_value_sleep = Boolean.valueOf(lp.getProperty("terminationhitvaluesleep", "false")).booleanValue();
		termination_not_improved = Boolean.valueOf(lp.getProperty("terminationnotimproved", "false")).booleanValue();
		termination_value_is_reached = (lp.getProperty("terminationvalueisreached") == null) ? Double.MIN_VALUE : Double.valueOf(lp.getProperty("terminationvalueisreached")).doubleValue();

				
		statistic_n_evaluation = Boolean.valueOf(lp.getProperty("statisticnevaluation", "true")).booleanValue();
		statistic_time = Boolean.valueOf(lp.getProperty("statistictime", "true")).booleanValue();
		statistic_best = Boolean.valueOf(lp.getProperty("statisticbest", "true")).booleanValue();
		statistic_avg = Boolean.valueOf(lp.getProperty("statisticavg", "true")).booleanValue();
		statistic_sample = Long.valueOf(lp.getProperty("statisticsample", "1000")).longValue();
		
		
		logfile = lp.getProperty("logfile", "");
		

	}
	
	public static void setBounds(){
		if(lower_bound != upper_bound) {
			// When lower and upper bounds are provided in the corresponding 
			// "lowerbound" and "upperbound" properties, it means that those bounds are equal for every dimension
			bounds = new double[N*2];
			for(int i=0;i<N*2;i+=2){
				bounds[i] = lower_bound;
				bounds[i+1] = upper_bound;
			}	
		}else{
			// Otherwise "lowerbound" and "upperbound" are not in the prop. file so "-1==-1"
			// Therefore, values should be fetched through the property "bounds"
			bounds=fetchArrayOfBounds("bounds");
		}
	}
	
	// An upper and lower bound for each dimension. E.g. bounds=-100,100;-5,50;0,10
	private static double[] fetchArrayOfBounds(String propertyName) {
		  String[] a = prop.getProperty(propertyName).split(";");
		  double[] bounds = new double[a.length*2];
		  for(int i = 0;i < a.length;i++) {
			String[] array = a[i].split(",");
		    bounds[i*2] = Double.valueOf((array[0]));
		    bounds[(i*2)+1] = Double.valueOf((array[1]));
		  }
		  return bounds;
		}
	
	

}
